package com.payment.service.impl;

import com.payment.entity.Office;
import com.payment.entity.OfficeWithDoctorDTO;
import com.payment.mapper.OfficeMapper;
import com.payment.service.OfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;


@Service
public class OfficeServiceImpl implements OfficeService {

    @Autowired
    private OfficeMapper officeMapper;


    @Override
    public List<OfficeWithDoctorDTO> getOfficeWithDoctor() {

        List<OfficeWithDoctorDTO> _list =officeMapper.getOfficeWithDoctor();
        List<OfficeWithDoctorDTO> res = new ArrayList<>();

        if (_list!=null){
            for (OfficeWithDoctorDTO item : _list) {
                if (item.getIsDelActive()==0 && item.getDoctorIsDelActive()==0){  //如果没被删除就添加到新的集合
                    res.add(item);
                }
            }
            return res;
        }
        return null;
    }

    @Override
    public List<Office> getAll() {
        List<Office> _list =officeMapper.getAll();
        List<Office> res = new ArrayList<>();

        if (_list!=null){
            for (Office item : _list) {
                if (item.getIsDelActive() == 0) { // 只添加未删除的用户
                    res.add(item);
                }
            }
            return res;
        }
        return null;
    }

    @Override
    public Office getById(int id) {
        return officeMapper.getById(id);
    }

    @Override
    public int add(Office entity) {
        int res = officeMapper.add(entity);
        if (res>0){
            return res;
        }
        return 0;
    }

    @Override
    public int update(Office entity) {
        return officeMapper.update(entity);
    }

    @Override
    public int del(int id) {
        return officeMapper.del(id);
    }
}